<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑流程</title>
    <link rel="stylesheet" type="text/css"
          href="${basePath}/static/css/production.css?v=${version}"/>
</head>
<body>
<div class="body-main">
    <div class="titleSearch add-title">
        <form id="flowEdit" action="">
            <input type="hidden" name="flowId" value="${ScFlow.id}"/>
            <div class="title-list">
                <label style="width: 120px"><span style="color: red">*</span>所属事业部：</label>
                <div class="layui-inline select2-inline">
                    <div class="layui-input-inline">
                        <input type="text" style="width: 180px" class="input-style" autocomplete="off"
                               id="selectTreeAddressIdEdit" name="selectTreeAddressIdEdit"
                               data-id="${ScFlow.deptIds}" data-orgid="" placeholder="请选择最下级的所属事业部"/>
                    </div>
                </div>
            </div>
            <div class="title-list">
                <label style="width: 120px"><span style="color: red">*</span>业态：</label>
                <div class="layui-inline">
                    <div id="business_typeCode">
                        <input type="hidden" name="typeCodeId" class="plug-in-msg" value=""/>
                        <input type="hidden" name="typeCodeEdit" id="typeCodeEdit" class="plug-in-code" value="${ScFlow.businessCode}"/>
                        <input type="text" readonly placeholder="请选择业态" class="chose-plugIn layui-input" name="businessTypeName" value="${ScFlow.businessName}">
                        <div class="bus-picker">
                            <div class="bus-picker-tab">
                                <a href="javascript:void(0);" class="active">请选择业态</a>
                            </div>
                            <div class="bus-picker-content"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="title-list">
                <label style="width: 120px"><span style="color: red">*</span>业务办理周期：</label>
                <div class="layui-inline">
                    <label class="input-unit">
                        <input type="text" class="input-style" name="blDate" value="${ScFlow.managementCycle}"
                        />
                        <span class="unit">天</span>
                    </label>
                </div>
            </div>
            <div class="title-list">
                <label style="width: 120px">工作日/自然日：</label>
                <div class="layui-inline">
                    <select class="select-style" name="isnaturalorworkday">
                        <option value="1" <c:if test="${ScFlow.isnaturalorworkday==1}">selected</c:if>>工作日</option>
                        <option value="2" <c:if test="${ScFlow.isnaturalorworkday==2}">selected</c:if>>自然日</option>
                    </select>
                </div>
            </div>
            <div class="title-list">
                <label style="width: 120px">审核级数：</label>
                <div class="layui-inline">
                    <select class="select-style" name="examinGrade">
                        <option value="1" <c:if test="${ScFlow.examineGrade==1}">selected</c:if>>一级</option>
                        <option value="2" <c:if test="${ScFlow.examineGrade==2}">selected</c:if>>二级</option>
                        <option value="3" <c:if test="${ScFlow.examineGrade==3}">selected</c:if>>三级</option>
                        <option value="4" <c:if test="${ScFlow.examineGrade==4}">selected</c:if>>四级</option>
                        <option value="5" <c:if test="${ScFlow.examineGrade==5}">selected</c:if>>五级</option>
                        <option value="6" <c:if test="${ScFlow.examineGrade==6}">selected</c:if>>六级</option>
                        <option value="7" <c:if test="${ScFlow.examineGrade==7}">selected</c:if>>七级</option>
                        <option value="8" <c:if test="${ScFlow.examineGrade==8}">selected</c:if>>八级</option>
                        <option value="9" <c:if test="${ScFlow.examineGrade==9}">selected</c:if>>九级</option>
                        <option value="10" <c:if test="${ScFlow.examineGrade==10}">selected</c:if>>十级</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <%--<div class="layui-layer-btn layui-layer-btn-" style="text-align: center">
        <a class="layui-layer-btn0" onclick="flowEdit()">确定</a>
        <a class="layui-layer-btn1" onclick="parent.layer.closeAll()">取消</a>
    </div>--%>
</div>

<script type="text/javascript">
    var isSyb = false;
    //属性初始化
    $(function () {
        $('#selectTreeAddressIdEdit').selectTree({
            check: false,   //默认为false，单选；设置为 true ，为多选
            search: true,
            parentIsCheck: true,
            url: cmsBaseUrl + "/api/cms/org/v1/find_all_parent_orgs.do?level=ORG_LEVEL_1&isFilterAB=1",//请求路 径
            form: true,
            idName: 'orgId',
            idKey: "id",//指定id
            pIdKey: "pId",//指定pId
            dataFilter: function (treeId, parentNode, responseData) {
                return responseData.data;
            },
            changeFun: function () {
                // 选择的不是事业部
                if (!findOrgInfo($('[name="selectTreeAddressIdEdit"]').attr("data-id"))) {
                    DGG.Warning('请选择层级为事业部的部门！');
                    // $('[name="selectTreeAddressIdCopy"]').attr("data-id","");
                    // $('[name="selectTreeAddressIdCopy"]').val("");
                    isSyb = false;
                } else {
                    isSyb = true;
                }
            }

        });
        //初始化下拉数据
    });
    $(document).ready(function () {
        Plug.plug_ins("post", "${basePath}/zzsc/common/tree_book_list.do?code=BUS_YT_ZZ&&type=2&&level=2", "#business_typeCode", '选择业态', '', true, 'BUS_YT_ZZ', '', '${ScFlow.businessCode}');

    });

    function flowEdit() {
        var addressDeptId = $('[name="selectTreeAddressIdEdit"]').val();
        var busYtCode = $('[name="typeCodeEdit"]').val();
        var blDate = $('[name="blDate"]').val();
        var isnaturalorworkday = $('[name="isnaturalorworkday"]').val();
        var examinGrade = $('[name="examinGrade"]').val();

        var busYtName = $('[name="typeCodeEdit"]').find("option:selected").text();

        if(blDate==0){
            DGG.Warning('办理周期不能为零！');
            return;
        }

        // if (!addressDeptId) {
        //     DGG.Warning('请选择所属事业部！');
        //     return;
        // }
        isSyb = findOrgInfo($('[name="selectTreeAddressIdEdit"]').attr("data-id"));
        if (!isSyb) {
            DGG.Warning('请选择层级为事业部的部门！');
            return;
        }
        if (!busYtCode) {
            DGG.Warning('请选择业态！');
            return;
        }

        //判断业态是否选择到最下级
        /* var n = (busYtCode.split('_')).length - 1;
         if (n != 3) {
             DGG.Layer.message('请选择正确的业态！', {icon: '0'});
             return;
         }*/

        if (!blDate) {
            DGG.Warning('请选择业务办理周期！');
            return;
        }
        if (!isIntGte('[name="blDate"]', false)) return flag = false;
        if (!isInLength('[name="blDate"]', 0, 5)) return flag = false;

        var params = $('#flowEdit').serializeArray();
        DGG.Confire("确定保存流程吗？", '操作', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: params,
                url: sysInfo.basePath + '/zzsc/flownode/edit_flow_save.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！');
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable1();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Warning('保存失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }

</script>
</body>
</html>
